package com.qj.yantaishan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.R;
import com.qj.yantaishan.domain.StoreNewsCategory;
import com.qj.yantaishan.service.IStoreNewsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Menglin
 */
@RestController
@RequestMapping("/yantaishan/StoreNewsCategory")
public class StoreNewsCategoryController extends BaseController {
    private String prefix = "yantaishan/StoreNewsCategory";

    @Autowired
    private IStoreNewsCategoryService storeNewsCategoryService;

    @GetMapping("list")
    public R getStoreNewsCategoryList(@RequestParam(required = false, defaultValue = "1") Integer currentPage,
                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Page<StoreNewsCategory> storeNewsCategoryPage = new Page<>(currentPage, pageSize);
        final Page<StoreNewsCategory> page = storeNewsCategoryService.page(storeNewsCategoryPage);
        return R.ok(page);
    }

    @PostMapping
    public R add(@RequestBody StoreNewsCategory storeNewsCategory) {
        storeNewsCategory.setAddTime(System.currentTimeMillis()/1000);
        return R.ok(storeNewsCategoryService.save(storeNewsCategory));
    }

    @PutMapping()
    public R update(@RequestBody StoreNewsCategory storeNewsCategory) {
        return R.ok(storeNewsCategoryService.updateById(storeNewsCategory));
    }

    @DeleteMapping()
    public R delete(@RequestParam(required = true) Integer newsCategoryId) {
        return R.ok(storeNewsCategoryService.removeById(newsCategoryId));
    }

}
